refactor(server): refactor error handling using http code enum#6409
refactor(server): refactor error handling using http code enum#6409chenjiahan merged 5 commits intomainfrom
Conversation
✅ Deploy Preview for rsbuild ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull Request Overview
This PR refactors error handling in the assets middleware by introducing an HttpCode enum to replace magic numbers and improves logging for specific error cases.
- Introduced
HttpCodeenum to replace hardcoded HTTP status codes throughout the middleware - Added explicit error logging for malicious paths (403) and invalid pathnames (400)
- Refactored
sendErrorfunction to acceptHttpCodeenum values and moved error message mapping inside the function
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/core/src/server/assets-middleware/middleware.ts | Introduced HttpCode enum, refactored sendError function signature, replaced magic numbers with enum values, and added error logging for BadRequest cases |
| packages/core/src/server/assets-middleware/getFileFromUrl.ts | Updated return type to use HttpCode enum, inlined pathname decoding logic, and replaced magic numbers with enum values |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Summary
HttpCodeenumChecklist